/*
    Copyright (c) 2003-2016 Pentair Technical Products, Inc.
    All rights reserved.
    Pentair Technical Products, Inc. proprietary and confidential.

    Description:
	This header file declared the functions
	provided by the library.

    $Revision: 13617 $
*/
#ifndef __LIB_H__
#define __LIB_H__

/* Standard library stuff */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#ifdef CFG_AST_MODEL


#include <errno.h>
#else
extern int errno;
#define EINVAL 22 /* Invalid argument */
#define ERANGE 34 /* The resulting value was out of range. */

extern int memcmp(const void *s1, const void *s2, size_t size);
extern void *memcpy(void *dst, const void *src, size_t size);
extern void *memmove(void *dst, const void *src, size_t size);
extern void *memset(void *s, int c, size_t size);


#define bzero(s, n)	(void)memset((s), 0, (n))
#define bcopy(d, s, n)	(void)memcpy((s), (d), (n))

extern char *strncpy(char *dst, const char *src, size_t maxlen);
extern size_t strnlen(const char *str, size_t maxlen);
extern int strncmp(const char *str1, const char *str2, size_t maxlen);

extern long strtol(const char *nptr, char **endptr, int radix);
extern unsigned long strtoul(const char *nptr, char **endptr, int radix);
extern double strtod(const char *nptr, char **endptr);

#if defined(CFG_SDI_ENABLE)
extern int printf(const char *fmt, ...)
	__attribute__ ((format (printf, 1, 2)));
extern int puts(const char *s);
extern int putchar(int c);
#endif /* defined(CFG_SDI_ENABLE) */

extern int serial_printf(char channel, const char *fmt, ...)
	__attribute__ ((format (printf, 2, 3)));
extern int snprintf(char *str, size_t len, const char *fmt, ...)
	__attribute__ ((format (printf, 3, 4)));

#endif /* CFG_AST_MODEL */

/* Proprietary stuff */

extern unsigned char checksum(const void *buf, unsigned long cb);
extern unsigned char checksum_P(unsigned long addr, unsigned long cb);
void hex_dump_ext(const void *data, unsigned short len, unsigned short width,
	const char *pfx, const char *sfx);
extern unsigned char crc8(unsigned char const *buf, int size);
extern unsigned char crc32(unsigned long crc,
	unsigned char const *buf, int size);
extern unsigned char find_first_bit(unsigned int mask);
void hex_dump(const unsigned char *data, unsigned short len);
extern char hex2int(unsigned char ch);

extern unsigned long powui(unsigned int b, unsigned int n);

extern char *hex_to_str(unsigned char hex, char *str);

#endif /* __LIB_H__ */
